package lec08ds;

public class BiLinkedList {
    static class Node {
        int data;
        Node pre;
        Node next;

        public Node(int data, Node pre, Node next) {
            this.data = data;
            this.pre = pre;
            this.next = next;
        }

        public Node(int data) {
            this(data, null, null);
        }
    }

    Node head = null;
    Node tail = null;
    int size = 0;


    public static void main(String[] args) {
        BiLinkedList list = new BiLinkedList();
        for (int i = 0; i < 10; i++) {
            list.addLast(new Node(i));
        }
        Node node = list.head;
        while (node != null) {
            System.out.print(node.data);
            node = node.next;
        }
        System.out.println();
        //   list.show2();
        node = list.tail;
        while (node != null) {
            System.out.print(node.data);
            node = node.pre;
        }
        System.out.println();

    }

    void addLast(Node node) {
        if (head == null) {
            head = tail = node;
            node.pre = null;
            node.next = null;
            ++size;
            return;
        }

        tail.next = node;
        node.pre = tail;
        tail = node;
        ++size;
        return;
    }
}

